package reflect;

import java.lang.reflect.Method;
import java.util.Scanner;

public class ReflectDemo4 {
    public static void main(String[] args) throws Exception {
      /*  Person p = new Person();
        p.sayHello();

        Class cls = Class.forName("reflect.Person");
        Object obj = cls.newInstance();
        //通过类对象获取方法对象
        Method m = cls.getMethod("sayHello");
        m.invoke(obj);  */     //obj.sayHello ();

        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个类名:");
        String classname = scan.nextLine();
        System.out.println("请输入一个方法名:");
        String methodName = scan.nextLine();

        Class cls = Class.forName(classname);
        Object obj = cls.newInstance();
        Method method = cls.getMethod(methodName);
        method.invoke(obj);

    }
}
